﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace comm_num_tp1
{
    public class SateliteInfoList : IEnumerator
    {
        #region private variables
        SateliteInfo[] _mySatelites;
        private int _arrayIndex = -1;
        #endregion

        #region constructor
        public SateliteInfoList()
        {
            Count = 0;
        }
        #endregion
        #region accessors
        public object Current
        {
            get
            {
                return _mySatelites[_arrayIndex];
            }
        }
        public SateliteInfo this[int n]
        {
            get
            {
                if (n >= 0 && n < _mySatelites.Length)
                    return _mySatelites[n];
                else
                    return null;
            }

        }

        public int Count { get; set; }
        #endregion

        #region public methods
        public IEnumerator GetEnumerator()
        {
            return this;
        }

        public bool MoveNext()
        {
            _arrayIndex++;
            if (_arrayIndex < _mySatelites.Length)
                return true;
            else
                return false;
        }

        public void Reset()
        {
            _arrayIndex = -1;
        }

        public void AddSatelite(SateliteInfo sInfo)
        {
            if (_mySatelites == null)
            {
                _mySatelites = new SateliteInfo[1];
                _mySatelites[0] = sInfo;
            }
            else
            {
                SateliteInfo[] sTemp = _mySatelites;
                _mySatelites = new SateliteInfo[sTemp.Length + 1];
                for (int i = 0; i < sTemp.Length; i++)
                    _mySatelites[i] = sTemp[i];
                _mySatelites[sTemp.Length] = sInfo;
            }
            Count++;
        }

        public void RemoveAllSatelite()
        {
            _mySatelites = null;
            Count = 0;
        }
        #endregion
    }
}
